#include <iostream>
#include <string>

#include "test.pb.h"

int main() {

    // 创建 Protobuf 对象
    fixbug::LoginRequest req;
    req.set_name("wuxf");
    req.set_pwd("23456");

    // 序列化
    int size = req.ByteSize();
    char str[size] = {0};
    if ( req.SerializeToArray(str, sizeof(str)) )
    {
        std::cout << str << std::endl;
    }


    // 反序列化
    fixbug::LoginRequest req1;

    if (req1.ParseFromArray(str, size))
    { // 直接用 string 反序列化
        std::cout << "Deserialized data:" << std::endl;
        std::cout << "Name: " << req1.name() << std::endl;
        std::cout << "Password: " << req1.pwd() << std::endl;
    }

    return 0;
}
